<style>
.con {
  margin-top: 50px;
  /* display: flex;
    justify-content: center;
    align-items: center; */
  /* margin-top: 100px; */
  /* border: 1px solid #ccc; */
}
</style>
<template>
  <div class="con">
    <el-form
      ref="form"
      :model="proNewProcure"
      :rules="rules"
      label-width="150px"
    >
      <el-col :span="6">
        <el-form-item label="货号" prop="productNo">
          <el-input
            v-model="proTemplate.productNo"
            placeholder="请输入货号"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="产品图" prop="picUrl">
          <image-preview
            :src="proTemplateSecondry.picUrl"
            :width="80"
            :height="80"
          />
        </el-form-item>
        <!-- //-----------新增或修改方法里上传图片 v-show="scope.row.picUrl"-->
        <!-- <el-form-item label="图片地址" prop="picUrl">
                <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                                                                        :on-exceed="handleExceed" :on-success="handlePictureSuccessPic" :before-upload="beforeAvatarUpload"
                                                                                                                                                                                                                                                        :on-preview="handlePictureCardPreview" :file-list="files">
                                                                                                                                                                                                                                                        <i class="el-icon-plus"></i>
                                                                                                                                                                                                                                                    </el-upload>
                                                                                                                                                                                                                                                <el-dialog :visible.sync="dialogVisible">
                                                                                                                                                                                                                                                    <img width="100%" v-if="picUrl" :src="picUrl" alt="">
                                                                                                                                                                                                                                                </el-dialog>
                                                                                                                                                                                                                                            </el-form-item> -->
        <el-form-item label="颜色属性" prop="colorPropertyStr">
          <!-- <el-input v-model="proTemplate.colorPropertyStr" placeholder="请输入颜色属性" :disabled="true" /> -->
          <el-input
            v-model="proTemplate.colorPropertyStr"
            placeholder="请输入颜色属性"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 12 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="面料成分" prop="fabricComposition">
          <el-input
            v-model="proTemplate.fabricComposition"
            placeholder="请输入面料成分"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 4 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-面料名称" prop="designFabricName">
          <el-input
            v-model="proTemplate.designFabricName"
            placeholder="请输入设计-面料名称"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-尺码" prop="designSize">
          <el-input
            v-model="proTemplate.designSize"
            placeholder="请输入设计-尺码"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 12 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-洗涤说明" prop="designWashing">
          <el-input
            v-model="proTemplate.designWashing"
            placeholder="设计-洗涤说明"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 12 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>
        <!-- <el-select v-model="proTemplate.designFabricName" placeholder="请选择面料名称" clearable>
                    <el-option v-for="dict in mianliao" :key="dict" :label="dict" :value="dict" />
                </el-select> -->
        <!-- <el-input v-model="proTemplate.designFabricName" placeholder="请输入设计-面料名称" @blur="updateData"
                                                                                                            @keyup.enter.native="enterBlur($event)" /> -->
        <!-- <el-select style="width:100%" v-model="proTemplate.designFabricName" filterable remote
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                :loading='lodingy' allow-create @visible-change="editSelect" default-first-option
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                :remote-method="remoteMethod" placeholder="请选择过滤内容" blur="updateData"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @keyup.enter.native="enterBlur($event)">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <el-option v-for="item in options" :key="item" :value="item">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </el-option>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    </el-select> -->

        <!-- <el-form-item label="尺寸" prop="proTemplateSizeList">
                <el-checkbox-group v-model="checked" @change="test">
                    <el-checkbox v-for="item in checkList" :key="item.id" :label="item.id" :disabled="true">{{
                        item.label }}
                        </el-checkbox>
                    </el-checkbox-group>

                  
                </el-form-item>
                <el-form-item label="logo图片" prop="picUrl">
                    <template #default="scope">
                        <el-popover effect="light" trigger="hover" placement="right" width="auto">
                            <template #default>
                                <img :src='pjtUrl + proTemplateSecondry.logoUrl'
                                    style="object-fit: contain;width: 300px;height: 200px;">
                                                                                                                            </template>
                                                                                                                            <template #reference>
                            <img :src='pjtUrl + proTemplateSecondry.logoUrl'
                                style="object-fit: contain;width: 100px; height: 100px" />
                        </template>
                    </el-popover>
                </template>
            </el-form-item> -->
        <!-- //-----------新增或修改方法里上传图片 -->
        <!-- <el-form-item label="logo图片" prop="logoUrl">
                <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                                                                        :on-exceed="handleExceed" :on-success="handlePictureSuccess" :before-upload="beforeAvatarUpload"
                                                                                                                                                        :on-preview="handlePictureCardPreview" :file-list="fileList">
                                                                                                                                                        <i class="el-icon-plus"></i>
                                                                                                                                                                                                                                                    </el-upload>
                                                                                                                                                                                                                                                    <el-dialog :visible.sync="dialogVisible">
                                                                                                                                                                                                                                                        <img width="100%" v-if="imageUrl" :src="imageUrl" alt="">
                                                                                                                                                                                                                                                    </el-dialog>
                                                                                                                                                                                                                                                </el-form-item> -->
        <!-- <el-form-item label="生产厂家代码" prop="manufacturerCode">
                                                                                                                    <el-input v-model="proTemplate.manufacturerCode" placeholder="请输入生产厂家代码" :disabled="true" />
                                                                                            </el-form-item> -->
      </el-col>
      <el-col :span="1"><el-form-item></el-form-item></el-col>
      <el-col :span="6">
        <el-form-item
          label="设计-属性类别/商品描述"
          prop="designPropertyCategory"
          label-width="170px"
        >
          <!--@blur="updateData" @keyup.enter.native="enterBlur($event)" <el-input v-model="proTemplate.designPropertyCategory" placeholder="请输入设计-属性类别/商品描述" /> -->
          <!-- <el-input v-model="proTemplate.designPropertyCategory" placeholder="请输入属性类别" @change="change"/> -->
          <!-- <el-select v-model="proTemplate.designPropertyCategory" placeholder="请选择属性类别" clearable>
                        <el-option v-for="dict in shuxing" :key="dict.value" :label="dict.attributesValue"
                            :value="dict.attributesValue" />
                    </el-select> -->
          <el-input
            v-model="proTemplate.designPropertyCategory"
            placeholder="请输入设计-属性类别/商品描述"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-版型/罩杯" prop="designFitCup">
          <!-- <el-input v-model="proTemplate.designFitCup" placeholder="请输入设计-版型/罩杯" @change="change"/> -->
          <!-- <el-select v-model="proTemplate.designFitCup" placeholder="请选择版型/罩杯" clearable>
                                                                                                    <el-option v-for="dict in banxing" :key="dict.value" :label="dict.attributesValue"
                            :value="dict.attributesValue" />
                    </el-select> -->
          <el-input
            v-model="proTemplate.designFitCup"
            placeholder="请输入设计-版型/罩杯"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-适合体型" prop="designSuitableBody">
          <!-- <el-input v-model="proTemplate.designSuitableBody" placeholder="请输入设计-适合体型" @change="change"/> -->
          <!-- <el-select v-model="proTemplate.designSuitableBody" placeholder="请选择适合体型" clearable>
                        <el-option v-for="dict in attributesList" :key="dict.value" :label="dict.attributesValue"
                            :value="dict.attributesValue" />
                    </el-select> -->
          <el-input
            v-model="proTemplate.designSuitableBody"
            placeholder="请输入设计-适合体型"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-衣长/裤长" prop="designGarmentTrouser">
          <el-input
            v-model="proTemplate.designGarmentTrouser"
            placeholder="请输入设计-衣长/裤长"
            :disabled="true"
          />
          <!-- <el-select v-model="proTemplate.designGarmentTrouser" placeholder="请选择适合衣长/裤长" clearable>
                                                                                                    <el-option v-for="dict in yichang" :key="dict.value" :label="dict.attributesValue"
                                                                                                        :value="dict.attributesValue" />
                                                                                                </el-select> -->
          <!-- <el-input v-model="proTemplate.designSuitableBody" placeholder="请输入设计-适合体型" :disabled="true" /> -->
        </el-form-item>
        <el-form-item label="设计-运动强度" prop="designExerciseIntensity">
          <el-input
            v-model="proTemplate.designExerciseIntensity"
            placeholder="请输入设计-运动强度"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-弹性" prop="designFlexibility">
          <el-input
            v-model="proTemplate.designFlexibility"
            placeholder="请输入设计-弹性"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-健身层级" prop="designFitnessLevels">
          <el-input
            v-model="proTemplate.designFitnessLevels"
            placeholder="请输入设计-健身层级"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-体感" prop="designSomatosensory">
          <el-input
            v-model="proTemplate.designSomatosensory"
            placeholder="请输入设计-体感"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-柔软度" prop="designSoftness">
          <el-input
            v-model="proTemplate.designSoftness"
            placeholder="请输入设计-柔软度"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-面料厚度" prop="designFabricThickness">
          <el-input
            v-model="proTemplate.designFabricThickness"
            placeholder="请输入设计-面料厚度"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-透气度" prop="designBreathability">
          <el-input
            v-model="proTemplate.designBreathability"
            placeholder="请输入设计-透气度"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-胸垫/裤裆" prop="designChestPad">
          <el-input
            v-model="proTemplate.designChestPad"
            placeholder="设计-胸垫/裤裆"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="设计-防震程度/腰高" prop="designShockproofDegree">
          <el-input
            v-model="proTemplate.designShockproofDegree"
            placeholder="设计-防震程度/腰高"
            :disabled="true"
          />
        </el-form-item>
      </el-col>
      <el-col :span="1"><el-form-item></el-form-item></el-col>
      <el-col :span="8">
        <el-form-item label="文案-功能展示" prop="copywritingFunctionDisplay">
          <el-input
            v-model="proTemplate.copywritingFunctionDisplay"
            placeholder="请输入文案-功能展示"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 12 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="文案-细节展示" prop="copywritingDetailShow">
          <el-input
            v-model="proTemplate.copywritingDetailShow"
            placeholder="请输入文案-细节展示"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 12 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="文案-设计原理" prop="copywritingDesignPrinciple">
          <el-input
            v-model="proTemplate.copywritingDesignPrinciple"
            placeholder="请输入文案-设计原理"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 12 }"
            :style="{ width: '100%' }"
            :disabled="true"
          />
        </el-form-item>

        <el-form-item
          label="视觉-是否拍3D图、细节"
          prop="visionShooting3d"
          label-width="170px"
        >
          <!-- <el-input v-model="proNewRelation.visionShooting3d" placeholder="请输入视觉-是否拍3D图、细节" /> -->
          <el-radio-group v-model="proNewRelation.visionShooting3d">
            <el-radio
              v-for="dict in dict.type.sys_one_zero"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="视觉-修图进度"
          prop="visionRetouchingProgress"
          label-width="170px"
        >
          <el-input
            v-model="proNewRelation.visionRetouchingProgress"
            placeholder="请输入视觉-修图进度"
          />
        </el-form-item>

        <el-form-item
          label="视觉-图片路径"
          prop="merchandiseTagPrice"
          label-width="170px"
        >
          <el-input
            v-model="proTemplate.visionPic"
            placeholder="请输入视觉-路径"
          />
        </el-form-item>
        <div class="footer" style="text-align: center">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel" style="margin-left: 30px"
            >返回上一级</el-button
          >
        </div>
      </el-col>
    </el-form>
  </div>
</template>
<script>
import {
  listRelation,
  getRelation,
  delRelation,
  addRelation,
  updateRelation,
} from "@/api/product/relation";

//--------导入token
import { getToken } from "@/utils/auth";
export default {
  name: "Purchase",
  dicts: ["sys_one_zero"],
  data() {
    return {
      proNewRelation: {},
      //图片相对路径
      picurl: "",
      //图片地址
      picUrl: "",
      //logo相对路径
      logoUrl: "",
      pjtUrl: process.env.VUE_APP_BASE_API,
      // 图片数量限制
      limit: 1,
      //页面上存的暂时图片地址List
      files: [{ url: "" }],
      //页面上存的暂时logo图片地址List
      fileList: [{ url: "" }],
      //图片地址
      imageUrl: "",
      dialogVisible: false,
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },
      checked: [],
      checkList: [
        { id: 1, label: "XS" },
        { id: 2, label: "S" },
        { id: 3, label: "M" },
        { id: 4, label: "L" },
        { id: 5, label: "XL" },
        { id: 6, label: "XXL" },
        { id: 7, label: "均码" },
        // { id: 0002, label: '汽车' },
        // { id: 0002, label: '火车' },
      ],
      // pjtUrl: process.env.VUE_APP_BASE_API,
      proTemplateSecondry: {}, //二级
      proTemplate: {}, //一级
      // 表单参数
      form: {
        // proNewProcure:
      },
      proNewProcure: {},
      // 表单校验
      rules: {},
    };
  },

  created() {
    // this.getList();
    this.handleUpdate();
  },
  methods: {
    test() {
      this.$modal.msgError("禁止修改尺寸");
    },
    /** 查询产品采购信息列表 */
    // getList() {
    //     this.loading = true;
    //     listPurchase(this.queryParams).then(response => {
    //         this.purchaseList = response.rows;
    //         this.total = response.total;
    //         this.loading = false;
    //     });
    // },
    // 取消按钮
    cancel() {
      this.$router.go(-1);
      // this.$router.push({ path: '/edit/new', query: { id: this.proTemplate.productNo } })
      return;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.files = undefined; //加的是这一行
      this.fileList = undefined; //加的是这一行
      this.proNewProcure = {
        id: null,
        proNewId: null,
        orderNum: null,
        orderTime: null,
        fabricCycle: null,
        workshopCycle: null,
        shippingTime: null,
        fabricComposition: null,
        isDelete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      // const id = row.id || this.ids
      const id = this.$route.query.id;
      if (!id) {
        this.$modal.msgError("请点击左侧菜单-上新管理进入");
        return;
      }
      getRelation(id).then((response) => {
        this.proNewRelation = response.data.proNewRelation;
        if (response.data.proNewProcure) {
          this.proNewProcure = response.data.proNewProcure;
        }

        //二级
        this.proTemplateSecondry = response.data.proTemplateSecondry;
        this.picurl = response.data.proTemplateSecondry.picUrl;
        this.logoUrl = response.data.proTemplateSecondry.logoUrl;
        //一级
        this.proTemplate = response.data.proTemplate;
        this.form = response.data;
        console.log(JSON.stringify(this.form));
        this.open = true;
        this.title = "修改产品采购信息";
        //图片回显
        this.files = [
          {
            url:
              process.env.VUE_APP_BASE_API +
              response.data.proTemplateSecondry.picUrl,
          },
        ]; //图片加的是这一行
        this.fileList = [
          {
            url:
              process.env.VUE_APP_BASE_API +
              response.data.proTemplateSecondry.logoUrl,
          },
        ]; //logo图片加的是这一行
        //尺寸回显

        if (
          response.data.proNewVO.proNewSizeList &&
          response.data.proNewVO.proNewSizeList.length > 0
        ) {
          let val = response.data.proNewVO.proNewSizeList.map((item) => {
            return item.size;
          });
          console.log(JSON.stringify(val));
          let m = [];
          for (let i = 0; i < val.length; i++) {
            // const element = array[i];
            this.checkList.forEach((item) => {
              if (val[i] == item.label) {
                m.push(item.id);
              }
            });
          }

          console.log(JSON.stringify(m));
          this.checked = m;
          // this.$set(this.form, 'checked', m)
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      // this.form.proTemplateSecondry.picUrl = this.picurl
      // this.form.proTemplateSecondry.logoUrl = this.logoUrl; // 注：重要(用于添加到数据库)，
      this.form.proNewProcure = this.proNewProcure;
      console.log(JSON.stringify(this.form));
      updateRelation(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        console.log(JSON.stringify(response));
        this.handleUpdate();
      });
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
          } else {
            // addPurchase(this.form).then(response => {
            //     this.$modal.msgSuccess("新增成功");
            //     this.open = false;
            //     this.getList();
            // });
          }
        }
      });
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg" || file.type == "image/png";
      const isLt2M = file.size / 1024 / 1024 < 5;
      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG/PNG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 5MB!");
      }
      return isJPG && isLt2M;
    },
    //图片预览
    handlePictureCardPreview(file) {
      this.picUrl = file.url;
      this.imageUrl = file.url;
      this.dialogVisible = true;
    },
    handlePictureSuccessPic(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      this.picUrl = file.response.url;
      // const url = file.response.fileName;
      this.picurl = file.response.fileName;
    },
    //图片上传成功后的回调
    handlePictureSuccess(res, file) {
      //设置图片访问路径 （url 后台传过来的的上传地址）
      this.imageUrl = file.response.url;
      // const url = file.response.fileName;
      this.logoUrl = file.response.fileName;
      // console.log(JSON.stringify(url));
    },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接LOGO图片数量不能超过 ${this.limit} 个!`);
    },
  },
};
</script>
<style lang="scss" scoped>
.el-input.is-disabled ::v-deep .el-input__inner {
  color: #606266;
  background-color: #f5f7fa;
  border: none;
  cursor: pointer;
}

.el-textarea.is-disabled ::v-deep .el-textarea__inner {
  color: #606266;
  background-color: #f5f7fa;
  border: none;
  cursor: pointer;
}
</style>